//
// Created by jsjxsy on 2022/8/22.
//
#include <fstream>
#include <iostream>
using namespace std;
bool readWriteFile() {
  string filename;
  cout << "enter file name for new file (eg:../data/xxx.txt) :" << endl;
  cin >> filename;
  ofstream fout(filename.c_str());
  if (fout) {
    perror("open file error:");
    return false;
  }
  fout << "For your eyes only!" << endl;
  cout << "Enter your secret number:" << endl;
  int number;
  cin >> number;
  fout << "your number is " << number << endl;
  fout.close();
  ifstream fin(filename.c_str());
  if (fin) {
    perror("open file error:");
    return false;
  }
  char ch;
  while (fin.get(ch)) {
    cout << ch;
  }
  cout << "Done" << endl;
  fin.close();
}

int main() {
  readWriteFile();
  return 0;
}